<?php if($this->errMsg) :?>
	<?php $this->showError($this->errMsg)?>
<?php endif;?>
<style>

</style>
	<div class="title_ad"><label><a href="">Danh sách chuyên mục</a></label></div>
	<div id="contenSort" align="center">
		<fieldset id="info">
		<legend >Sắp xếp thứ tự xuất hiện</legend>
			<ul class="ui-sortable">
				<?php 
				foreach($this->arrforumsort as $row)
				{
					echo "<li id='id_$row->id'>$row->name</li>";
				}
				?>
			</ul>
			<a style="text-align:right;float:right;margin-right:20px;" href="<?php echo $this->baseUrl()?>/admin/forum/new"><img src="<?php echo $this->baseUrl()?>/application/templates/admin/images/plus_32.png" /></a>
		</fieldset>		
			<div class="clear"></div>
	</div>
	<table  class="display" id="list">
	<thead>
		<tr>
			<th width="10px">ID</th>
			<th>Name</th>
			<th width="130px">Status</th>
			<th width="80px" style="text-align: center;">Tool</th>
		</tr>
	</thead>
	<tbody>
	<?php 
	foreach ($this->arrforum as $row)
	{
		$status = "";
		if($row->status == 1)
			$status = 'Hiện <a style="float:right;" href="javascript:hide('.$row->id.')" title="Ẩn comment này"><img src="'.$this->baseUrl().'/public/images/Unbanned.png"></img></a>';
		else
			$status = 'Ẩn <a style="float: right;" href="javascript:show('.$row->id.')" title="Hiện comment này"><img src="'.$this->baseUrl().'/public/images/Banned.png"></img></a>';
		echo("<tr>");
		echo(	"<td>".$row->id."</td>");
		echo(	"<td>".$row->name."</td>");
		echo(	"<td id='active_".$row->id."'>".$status."</td>");
		echo(	'<td><a href="'.$this->baseUrl().'/admin/forum/edit/id/'.$row->id.'" title="Edit" class="tool-16 edit"></a>&nbsp;&nbsp;
				<a href="javascript:del('.$row->id.')" title="Delete" class="tool-16 delete"></a></td>');
		echo("</tr>");
	}
	?>
	</tbody>
</table>
<script>
function hide(key){
	if(!confirm("bạn muốn ẩn chuyêm mục này không?"))
		return;
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/forum/status'?> ",
		data: "id=" + key +"&status=0",
		dataType: 'json',
		success: function(msg){
			if(msg)
			{	
				var data ='<fieldset id="info">';
				data += '<legend >Sắp xếp thứ tự xuất hiện</legend>';
				data += '	<ul class="ui-sortable">';
				$.each(msg, function(key, value){ 
					data += "<li id='id_"+value['id']+"'>"+value['name']+"</li>";
				});
				data += '	</ul>';
				data += '	<a style="text-align:right;float:right;margin-right:20px;" href="<?php echo $this->baseUrl()?>/admin/forum/new"><img src="<?php echo $this->baseUrl()?>/application/templates/admin/images/plus_32.png" /></a>';
				data += '</fieldset>	';	
				data += '	<div class="clear"></div>';
				$('#contenSort').html(data);
				$(function(){
					$("#contenSort ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
						var order = $(this).sortable("serialize"); 
						$.post("<?php echo $this->baseUrl.'/admin/forum/sort'?>", order, function(theResponse){
						}); 															 
					}								  
					});
				});
				$('#active_'+key).html('Ẩn<a style="float: right;" href="javascript:show('+key+')" title="Hiện chuyên mục này"><img src="<?php echo ($this->baseUrl().'/public/images/banned.png') ?>"></img></a>');
			}else
				alert('Error');
		}
	});
}

function show(key){
	if(!confirm("bạn muốn hiện chuyêm mục này không?"))
		return;
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/forum/status'?> ",
		data: "id=" + key +"&status=1",	
		dataType: 'json',
		success: function(msg){
			if(msg)
			{
				var data ='<fieldset id="info">';
				data += '<legend >Sắp xếp thứ tự xuất hiện</legend>';
				data += '	<ul class="ui-sortable">';
				$.each(msg, function(key, value){ 
					data += "<li id='id_"+value['id']+"'>"+value['name']+"</li>";
				});
				data += '	</ul>';
				data += '	<a style="text-align:right;float:right;margin-right:20px;" href="<?php echo $this->baseUrl()?>/admin/forum/new"><img src="<?php echo $this->baseUrl()?>/application/templates/admin/images/plus_32.png" /></a>';
				data += '</fieldset>	';	
				data += '	<div class="clear"></div>';
				$('#contenSort').html(data);
				$('#active_'+key).html('Hiện<a style="float: right;" href="javascript:hide('+key+')" title="Ẩn chuyện mục này"><img src="<?php echo ($this->baseUrl().'/public/images/Unbanned.png') ?>"></img></a>');
				$(function(){
					$("#contenSort ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
						var order = $(this).sortable("serialize"); 
						$.post("<?php echo $this->baseUrl.'/admin/forum/sort'?>", order, function(theResponse){
						}); 															 
					}								  
					});
				});
			}else
				alert('Error');
		}
	});
}
function del(key){
	if(!confirm("Bạn muốn xóa chuyên mục này không?"))
		return;
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/forum/delete'?> ",
		data: "id=" + key,	
		success: function(msg){
			if(msg == '1')
				location.replace("<?php echo $this->baseUrl.'/admin/forum/index'?>");
			else
				alert('Error');
		}
	});
}

$(document).ready(function(){
	$(function(){
		$("#contenSort ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
			var order = $(this).sortable("serialize"); 
			$.post("<?php echo $this->baseUrl.'/admin/forum/sort'?>", order, function(theResponse){
			}); 															 
		}								  
		});
	});
	
});
</script>